package com.leadership.api.service.impl;

import java.util.Date;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.demo2do.core.persistence.GenericDaoSupport;
import com.demo2do.core.persistence.annotation.Dao;
import com.leadership.api.dao.ActionLearningDao;
import com.leadership.api.service.ActionLearningService;
import com.leadership.entity.actionlearning.ActionLearning;
import com.leadership.entity.actionlearning.Status;

/**
 * 
 * @author dan
 *
 */
@Service("actionLearningService")
public class ActionLearningServiceImpl implements ActionLearningService{
    
    private static final Logger logger = LoggerFactory.getLogger(ActionLearningServiceImpl.class);
    
    @Dao
    private ActionLearningDao actionLearningDao;
    
    @Autowired
    private GenericDaoSupport genericDaoSupport;

    /*
     * (non-Javadoc)
     * @see com.leadership.scheduler.service.ActionLearningService#startActionLearning(java.util.Date)
     */
    public void startActionLearning(Date startDate) {
        // list action learning
        List<ActionLearning> actionLearnings = actionLearningDao.list(Status.CREATED, startDate);
        
        if(actionLearnings.isEmpty()) {
            logger.trace("#startActionLearning actionlearning is empty");
            return;
        }
        
        for(ActionLearning actionLearning : actionLearnings) {
            genericDaoSupport.update(actionLearning.changeStatus(Status.PROCESSING));
        }
        
    }

}
